import Vue from "vue";
import App from "./App";
import moment from "moment";

import uView from "uview-ui";
Vue.use(uView);

const { Get, Post, Put, http } = require("./request/index");
Vue.prototype.$http = http;
Vue.prototype.$get = Get;
Vue.prototype.$post = Post;
Vue.prototype.$put = Put;

//图片路径
//本地
Vue.prototype.$baseUrl =
  process.env.NODE_ENV === "development"
    ? "http://192.168.1.11:81/dev-api"
    : "http://140.210.78.20:8880/prod-api";

//抚州
// Vue.prototype.$baseUrl =
//   process.env.NODE_ENV === "development"
//     ? "http://172.26.110.66/prod-api"
//     : "http://172.26.110.66/prod-api";

//公司
// Vue.prototype.$baseUrl =
//   process.env.NODE_ENV === "development"
//     ? "http://114.242.193.103:8880/prod-api"
//     : "http://114.242.193.103:8880/prod-api";

Vue.prototype.$moment = moment;

//角色权限
Vue.prototype.$checkPerm = (value) => {
  if (value && value instanceof Array && value.length > 0) {
    const permissions = uni.getStorageSync("userPermissions");
    const permissionDatas = value;
    const all_permission = "*:*:*";

    const hasPermission = permissions.some((permission) => {
      return (
        all_permission === permission || permissionDatas.includes(permission)
      );
    });

    if (!hasPermission) {
      return false;
    }
    return true;
  } else {
    console.error(
      `need roles! Like checkPermi="['system:user:add','system:user:edit']"`
    );
    return false;
  }
};

Vue.config.productionTip = false;

App.mpType = "app";

const app = new Vue({
  ...App,
});
app.$mount();
